package com.qianbei.user.help;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.qianbei.R;

import java.util.ArrayList;

public class HelpAdapter extends ArrayAdapter<HelpBean> {
	private ArrayList<HelpBean> jsonList;
	private Context mContext;

	public HelpAdapter(Context mContext, ArrayList<HelpBean> objects) {
		super(mContext, 0, objects);
		this.jsonList = objects;
		this.mContext = mContext;
	}

	//

	// @Override
	// public View getView(final int position, View convertView, ViewGroup
	// parent) {
	// ViewHolder holder;
	// String jsonObject = jsonList.get(position);
	// if (convertView == null) {
	// convertView = LayoutInflater.from(getContext()).inflate(
	// R.layout.message_list_item, null);
	// holder = new ViewHolder();
	// holder.tv_addTime = (TextView) convertView
	// .findViewById(R.id.msg_tv_addTime);
	// convertView.setTag(holder);
	//
	// }// 如果当前视图为TextView,则重新生成一个convertView
	// else {
	// holder = (ViewHolder) convertView.getTag();
	// }
	// holder.tv_addTime.setText(jsonObject);
	// return convertView;
	// }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoldLeft holdLeft = null;

		final HelpBean jsonObject = jsonList.get(position);

		if (convertView == null) {
			holdLeft = new ViewHoldLeft();
			convertView = LayoutInflater.from(getContext()).inflate(
					R.layout.help_list_item, null);
			holdLeft.textView = (TextView) convertView
					.findViewById(R.id.help_content);
			holdLeft.title = (TextView) convertView
					.findViewById(R.id.help_title);
			convertView.setTag(holdLeft);
		} else {
			holdLeft = (ViewHoldLeft) convertView.getTag();
		}
		if (jsonObject.isShow) {
			holdLeft.textView.setVisibility(View.VISIBLE);
		} else {
			holdLeft.textView.setVisibility(View.GONE);
		}
		holdLeft.textView.setText(jsonObject.info);
		holdLeft.title.setText(jsonObject.title);
		
		holdLeft.textView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				jsonObject.isShow = false;
				notifyDataSetChanged();
			}
		});

		holdLeft.title.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (jsonObject.isShow) {
					jsonObject.isShow = false;
				} else {
					jsonObject.isShow = true;
				}
				notifyDataSetChanged();
			}
		});

		return convertView;

	}

	private static class ViewHoldLeft {
		private TextView textView, title;
	}

}